package cn.edu.hit.core.message;

import com.fasterxml.jackson.databind.JavaType;
import cn.edu.hit.core.Document;

import java.util.Collections;
import java.util.List;

public class AssignedAdapter extends MessageAdapterHelper2 {
    @Override
    public boolean accept(String type) {
        return "Assign".equalsIgnoreCase(type);
    }

    private static JavaType doubleListType = mapper.getTypeFactory().constructParametricType(List.class, Double.TYPE);

    @Override
    protected Object getValue(Object object, String id, Document configure) {
        String argString = configure.getString(DATA_SOURCE_ARGS);
        List<Double> value = Collections.emptyList();
        try {
            value = mapper.readValue(argString, doubleListType);
        } catch (Exception e) {
            e.printStackTrace();
            logger.warning("Channel " + id + " 的DataSourceArgs 无法解析为一个数值数组，使用空数组替代。 ");
        }
        return value;
    }
}
